package com.wg.msproductgz.controller;

import com.wg.msproductgz.entity.Product;

import com.wg.msproductgz.entity.otd.Pro;
import com.wg.msproductgz.mapper.ProductMapper;
import com.wg.msproductgz.service.ProductService;
import io.swagger.v3.oas.annotations.Parameter;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin(origins = "*")
public class ProductController {
    @Autowired
    private ProductService productService;
    @PostMapping("/product")
    public int insert(Product  product){
        Boolean result = productService.save(product);
        return result ? 1 : 0;
    }
    @GetMapping("/product/select/{id}")
    public Pro selects(@PathVariable("id") Integer id){
        return productService.select(id);
    }
    @GetMapping("/product/selects/change")
    public Product selects(@Parameter Integer shopId,@Parameter String name){
        return productService.selectOne(shopId,name);
    }
    @PutMapping("/update")
    public int update(Product product){
        Boolean result = productService.updateById(product);
        return result ? 1 : 0;
    }
    @DeleteMapping("/delete/{id}")
    public int delete(@PathVariable("id") Integer id){
        Boolean result = productService.removeById(id);
        return result ? 1 : 0;
    }
    @DeleteMapping("/product")
    public int delete(@RequestBody Product product){
        return productService.removeById(product)? 1 : 0;
    }
}
